#ifndef DEBUGTRACE_H
#define DEBUGTRACE_H

/**
 *\copyright Copyright(C),2024, Ningbo Tuopu Group Co., Ltd.
 *\file      *.h
 *\date      2025-04-13 00:00:00
 *\author    Chuhan Zheng
 *\version   1.0
 *\brief     Description:
 */

/****************************************************************************/
/*                             Include area                                 */
/****************************************************************************/
#include "DebugTrace_Type.h"

/****************************************************************************/
/*                             Definition area                              */
/****************************************************************************/
/* Define the maximum size of the log line buffer */
#define DEBUGTRACE_BUFFER_SIZE (128U)

#if (DEBUGTRACE_BUFFER_SIZE < 32U)
#error "DEBUGTRACE_BUFFER_SIZE Size Configuration Error"
#endif

/****************************************************************************/
/*                             Typedef area                                 */
/****************************************************************************/

typedef enum
{
  LOG_ACORE_PLT = 0x0000,
  LOG_ACORE_DRV = 0x0400,
  LOG_ACORE_APP = 0x0800,
  LOG_ACORE_RESERT = 0x0c00
} log_acore_base;

typedef enum
{
  LOG_BCORE_PLT = 0x1000,
  LOG_BCORE_DRV = 0x1400,
  LOG_BCORE_APP = 0x1800,
  LOG_BCORE_RESERT = 0x1c00
} log_bcore_base;

typedef enum
{
  LOG_CCORE_PLT = 0x2000,
  LOG_CCORE_DRV = 0x2400,
  LOG_CCORE_APP = 0x2800,
  LOG_CCORE_RESERT = 0x2c00
} log_ccore_base;

typedef enum
{
  LOG_IPC_BT_APP = 0x533018,
  LOG_IPC_APP_BT = 0x533019,
} log_ipc_base;

typedef enum
{
  LOG_ACORE_DEVICE_MINIOS = LOG_ACORE_DRV,
  LOG_MINIOS_APP = LOG_ACORE_DEVICE_MINIOS,
  LOG_MINIOS_CJSON,
  LOG_MINIOS_DEVICE,
  LOG_MINIOS_DRIVER,
  LOG_MINIOS_PRODUCT,
} log_minios;

typedef enum
{
  LOG_ACORE_DEVICE_NVM = LOG_ACORE_DRV + 0x40,
  LOG_NVM_APP = LOG_ACORE_DEVICE_NVM,
  LOG_NVM_CJSON,
  LOG_NVM_DEVICE,
  LOG_NVM_DRIVER,
  LOG_NVM_PRODUCT,
} log_nvm;

/****************************************************************************/
/*                             Local data at RAM                            */
/****************************************************************************/

/****************************************************************************/
/*                             Global data at RAM                           */
/****************************************************************************/

/****************************************************************************/
/*                        Global data at RAM declare area                   */
/****************************************************************************/

/****************************************************************************/
/*                             Local data at ROM                            */
/****************************************************************************/

/****************************************************************************/
/*                             Global data at ROM                           */
/****************************************************************************/

/****************************************************************************/
/*                        Global data at ROM declare area                   */
/****************************************************************************/

/****************************************************************************/
/*                        Local function declare area                       */
/****************************************************************************/
void DebugTrace_Packaging(DebugTrace_LogLevel level, const char *core_name, uint32_t combined_log_id, const char *fmt, int args_count, ...);
void DebugTrace_SyncTransmitEnable(void);
void DebugTrace_ASyncTransmitEnable(void);

/****************************************************************************/
/*                        Global function declare area                      */
/****************************************************************************/
/* Debug logs of IPC */
#define ACORE_IPC_LOG_DEBUG(log_id, ipc_type, ipc_direction, service, cmd, len, ts)               \
  DebugTrace_Packaging(LOG_LEVEL_DEBUG, "Acore", log_id,                                          \
                       "[%s] [%s] SERVICE_ID=0x%x, COMMAND_ID=0x%x, PAYLOAD_LEN=%d, BEGIN_TS=%d", \
                       6, ipc_type, ipc_direction, service, cmd, len, ts)

/* Debug logs of IPC */
#define BCORE_IPC_LOG_DEBUG(log_id, ipc_type, ipc_direction, service, cmd, len, ts)               \
  DebugTrace_Packaging(LOG_LEVEL_DEBUG, "Bcore", log_id,                                          \
                       "[%s] [%s] SERVICE_ID=0x%x, COMMAND_ID=0x%x, PAYLOAD_LEN=%d, BEGIN_TS=%d", \
                       6, ipc_type, ipc_direction, service, cmd, len, ts)

/* Information logs of MiniOS */
#define MINIOS_APP_PRINT_DEBUG(log_code, fmt, args_count, ...) \
  DebugTrace_Packaging(LOG_LEVEL_DEBUG, "Acore", DEBUGTRACE_CONNECT(LOG_MINIOS_APP, log_code), fmt, args_count, ##__VA_ARGS__)

/* Information logs of MiniOS */
#define MINIOS_APP_PRINT_INFO(log_code, fmt, args_count, ...) \
  DebugTrace_Packaging(LOG_LEVEL_INFO, "Acore", DEBUGTRACE_CONNECT(LOG_MINIOS_APP, log_code), fmt, args_count, ##__VA_ARGS__)

/* Warning logs of MiniOS */
#define MINIOS_APP_PRINT_WARN(log_code, fmt, args_count, ...) \
  DebugTrace_Packaging(LOG_LEVEL_WARN, "Acore", DEBUGTRACE_CONNECT(LOG_MINIOS_APP, log_code), fmt, args_count, ##__VA_ARGS__)

/* Error logs of MiniOS */
#define MINIOS_APP_PRINT_ERROR(log_code, fmt, args_count, ...) \
  DebugTrace_Packaging(LOG_LEVEL_ERROR, "Acore", DEBUGTRACE_CONNECT(LOG_MINIOS_APP, log_code), fmt, args_count, ##__VA_ARGS__)

/* Debug logs of NvM */
#define NVM_APP_PRINT_DEBUG(log_code, fmt, args_count, ...) \
  DebugTrace_Packaging(LOG_LEVEL_DEBUG, "Acore", DEBUGTRACE_CONNECT(LOG_NVM_APP, log_code), fmt, args_count, ##__VA_ARGS__)

/* Information logs of NvM */
#define NVM_APP_PRINT_INFO(log_code, fmt, args_count, ...) \
  DebugTrace_Packaging(LOG_LEVEL_INFO, "Acore", DEBUGTRACE_CONNECT(LOG_NVM_APP, log_code), fmt, args_count, ##__VA_ARGS__)

/* Warning logs of NvM */
#define NVM_APP_PRINT_WARN(log_code, fmt, args_count, ...) \
  DebugTrace_Packaging(LOG_LEVEL_WARN, "Acore", DEBUGTRACE_CONNECT(LOG_NVM_APP, log_code), fmt, args_count, ##__VA_ARGS__)

/* Error logs of NvM */
#define NVM_APP_PRINT_ERROR(log_code, fmt, args_count, ...) \
  DebugTrace_Packaging(LOG_LEVEL_ERROR, "Acore", DEBUGTRACE_CONNECT(LOG_NVM_APP, log_code), fmt, args_count, ##__VA_ARGS__)

#endif /* DEBUGTRACE_H */
